﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;

namespace LunchCommand.Models
{
    public class Lunch
    {
        public Lunch()
        {
            this.Users = new List<LunchUser>();
        }

        [Index]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public Int32 LunchId { get; set; }

        public Int32? VenueId { get; set; }

        public Int32? QuickVenueId { get; set; }

        public Int32? DissentingVenueId { get; set; }

        public DateTime LunchTime { get; set; }

        [ForeignKeyAttribute("VenueId")]
        public virtual Venue Venue { get; set; }

        [ForeignKeyAttribute("QuickVenueId")]
        public virtual Venue QuickVenue { get; set; }

        [ForeignKeyAttribute("DissentingVenueId")]
        public virtual Venue DissentingVenue { get; set; }

        public virtual ICollection<LunchUser> Users { get; set; }

        public Int32? PercentOfUsersAgreeing { get; set; }

        public Int32? PercentOfUsersDissenting { get; set; }

        public Int32? PercentOfUsersAgreeingToQuick { get; set; }

        [NotMapped]
        public IEnumerable<User> UsersGoing
        {
            get
            {
                return this.Users.Where(u => u.Decision).Select(u=>u.User).ToArray();
            }
        }
    }
}
